package redis

import (
	"cloudpichost/conf"
	"fmt"
	"github.com/go-redis/redis"
	"log"
)

var (
	Client *redis.Client
)

// 初始化 Redis 客户端
func Initialize() {
	Client = redis.NewClient(&redis.Options{
		Addr:     conf.Setting.RedisAddr,
		Password: conf.Setting.RedisPWD, // 没有设置密码时为空
		DB:       conf.Setting.RedisDB,  // 默认 DB
	})
	pong, err := Client.Ping().Result()
	if err != nil {
		log.Fatalf("Redis 连接失败: %v\n", err)
		//fmt.Printf("Redis 连接失败: %v\n", err) // 本地测试
	} else {
		fmt.Printf("Redis 连接成功: %s\n", pong)
	}
}
